package ssm.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ssm.dao.*;
import ssm.service.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class RegioninfoController {
    @Autowired
    private RegioninfoService regioninfoService;

    @Autowired
    private LocationCardService locationCardService;

    @Autowired
    private LocationCarService locationCarService;

    @Autowired
    private LocationFaceService locationFaceService;

    @Autowired
    private LocationWifiService locationWifiService;
    @Autowired
    private DeviceService deviceService;


    @RequestMapping(value = "/getTree", produces = "application/json;charset=utf-8")
    @ResponseBody
    public List<TreeJson> getTree() {
        List<TreeJson> jsons = regioninfoService.getTree();
        return jsons;
    }




    @RequestMapping(value = "/getAllTree")
    @ResponseBody
    public Map<String, Object> getNewTree(){
        Map<String,Object>result=deviceService.getTree();
        return result;
    }

    public List<Map> facesTorenlian(List<LocationFace> faces) {
        List<Map> list = new ArrayList<Map>();
        for (LocationFace face : faces) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", face.getDeviceid());
            map.put("text", face.getName());
            map.put("parent", face.getParentid());
            map.put("state", new OpenedState(false));
            map.put("type", face.getType());
            map.put("camerJd", face.getDevicejd());
            map.put("camerWd", face.getDevicewd());
            map.put("sfsn", face.getSfsn());
            map.put("indexCode", face.getIndexcode());
            map.put("buildName", face.getBuildname());
            list.add(map);
        }
        return list;
    }

    public List<Map> carsTokakou(List<LocationCar> cars) {
        List<Map> list = new ArrayList<Map>();
        for (LocationCar car : cars) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", car.getDeviceid());
            map.put("text", car.getName());
            map.put("parent", car.getParentid());
            map.put("state", new OpenedState(false));
            map.put("type", car.getType());
            map.put("camerJd", car.getDevicejd());
            map.put("camerWd", car.getDevicewd());
            map.put("sfsn", car.getSfsn());
            map.put("indexCode", car.getIndexcode());
            map.put("buildName", car.getBuildname());

            list.add(map);
        }
        return list;
    }

    public List<Map> cardsToykt(List<LocationCard> cards) {
        List<Map> list = new ArrayList<Map>();
        for (LocationCard card : cards) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", card.getDeviceid());
            map.put("text", card.getName());
            map.put("parent", card.getParentid());
            map.put("state", new OpenedState(false));
            map.put("type", card.getType());
            map.put("camerJd", card.getDevicejd());
            map.put("camerWd", card.getDevicewd());
            list.add(map);
        }
        return list;
    }

    public List<Map> Towifi(List<LocationWifi> wifis) {
        List<Map> list = new ArrayList<Map>();
        for (LocationWifi wifi : wifis) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", wifi.getDeviceid());
            map.put("text", wifi.getName());
            map.put("parent", wifi.getParentid());
            map.put("state", new OpenedState(false));
            map.put("type", wifi.getType());
            map.put("indexCode", wifi.getIndexcode());
            map.put("camerJd", wifi.getDevicejd());
            map.put("camerWd", wifi.getDevicewd());
            map.put("sfsn", wifi.getSfsn());
            map.put("buildName", wifi.getBuildname());
            list.add(map);
        }
        return list;
    }




}
